package cn.itcast.search.config;

import cn.itcast.hmall.config.MqConstants;
import cn.itcast.search.Service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//监听消息
@Component
public class RabbitListenerSearsh {

    @Autowired
    private SearchService searchService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.ITEM_UP_QUEUE),
            exchange = @Exchange(name = MqConstants.ITEM_TOPIC_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.ITEM_UP_ROUTING
    ))
    public void listenUpTopicQueue(Long id){
        searchService.up(id);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.ITEM_DOWN_QUEUE),
            exchange = @Exchange(name = MqConstants.ITEM_TOPIC_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.ITEM_DOWN_ROUTING
    ))
    public void listenDownTopicQueue(Long id){
        searchService.down(id);
    }




}
